package org.example.JUC.TimerTest;

import java.util.Timer;
import java.util.TimerTask;

/**
 * @description:
 * @author: farprt
 * @create: 2022-09-10 16:23
 **/
public class TimerTest {

    static class DelayTask extends TimerTask {

        @Override
        public void run() {
            System.out.println("delayed task");
        }
    }

    static class LongRunningTask extends TimerTask{
        @Override
        public void run() {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {

            }
            System.out.println("long running finished");
        }
    }

    static class FixedDelayTask extends TimerTask{
        @Override
        public void run() {
            System.out.println(System.currentTimeMillis());
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Timer timer=new Timer();

        timer.schedule(new LongRunningTask(),10,10);
        timer.scheduleAtFixedRate(new FixedDelayTask(),100,1000);

    }
}